/*
day86
2019.11.22
*/

struct TreeNode {
	int val;
	struct TreeNode *left;
	struct TreeNode *right;
}; 


class Solution {
public:
    TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) 
	{
        if(!root || root==p || root==q) return root;
        
        struct TreeNode *left = lowestCommonAncestor(root->left,p,q);
        
        struct TreeNode *right = lowestCommonAncestor(root->right,p,q);
        
        if(left && right) return root; 
        return left ? left : right;
    }
};


int main()
{
	return 0;
}
